<script type="text/javascript" src="<?php echo base_url(); ?>static/select2/select2.min.js" ></script>
<script type="text/javascript" src="<?php echo base_url(); ?>static/js/selectSearchGlobal.js"></script>

<?php
//echo 'tes aja'; exit;
    //QUERY 1
    $this->load->model('sGlobal_model');
    /*$hitungan=$this->sGlobal_model->hitungAja();
    foreach($hitungan as $htg){
        $jumlah=$htg['CNT'];
    }
    echo $jumlah; exit;
    */
    foreach ($getDetail as $row) {
        $vCtrlId		=	$row['CTRL_ID'] ;
    	$vCtrlUntukNik	=	$row['CTRL_UNTUK_NIK'] ;
    	$vCtrlCard		=	$row['CARD'] ;
    	$vCtrlTelp		=	$row['TELP'] ;
    	$vCtrlSikNo		=	$row['CTRL_SIK_NO'] ;
    	$vCtrlSDate		=	$row['CTRL_DATE_AWAL'] ;
    	$vCtrlEDate		=	$row['CTRL_DATE_AKHIR'] ;
    	$vCtrlCDate		=	$row['DTMUPD'] ;
    	$vCtrlAtasanNik	=	$row['CTRL_ATASAN_ID'] ;
    	$vCtrlDesc		=	$row['CTRL_DESCRIPTION'] ;
           $vCtrlPhoneFisik	=	$row['CTRL_TELP_FISIK'];
    	$vCtrlCardFisik	=	$row['CTRL_CARD_FISIK'];
    	
    	$aAtasanName 		= $row['ATASANNAME'];
    	$cName				= $row['NIKNAME'];
    	$cJob				= $row['NIKJOBPOSITION'];
    	$cOrg				= $row['NIKORG'];
    }
    
?>

<script type="text/javascript" language="javascript">
$(document).ready(function()
{
	$('input[type="checkbox"]').change(function(e) 
	{
		var checked = $(this).prop("checked"),
		container = $(this).parent(),
		siblings = container.siblings();	
		container.find('input[type="checkbox"]').prop({indeterminate: false,checked: checked});
		
		function checkSiblings(el)
		{
			var parent = el.parent().parent(),
			all = true;
			el.siblings().each(function() {return all = ($(this).children('input[type="checkbox"]').prop("checked") === checked);});
			if (all && checked) 
			{
				parent.children('input[type="checkbox"]').prop({indeterminate: false,checked: checked});
				checkSiblings(parent);
			} 
			else if (all && !checked) 
			{
				parent.children('input[type="checkbox"]').prop("checked", checked);
				parent.children('input[type="checkbox"]').prop("indeterminate", (parent.find('input[type="checkbox"]:checked').length > 0));
				checkSiblings(parent);
			} 
			else
			{
				el.parents("li").children('input[type="checkbox"]').prop({indeterminate: true,checked: true});
			}
		}
		checkSiblings(container);
	});
});
</script>

<!-- OPEN JIKA MENGGUNAKAN G_Date-->
<!--<script type="text/javascript" src="<?php echo base_url(); ?>static/js/select.js" /></script>
-->

<script type="text/javascript">

    $(document).ready(function() {
        $('#pAtasanNama').select2({
            placeholder: "",
            allowClear: true
        });
        $('#pCtrlSik').select2({
            placeholder: "",
            allowClear: true
        });
    });

    


</script>

<script>
	$(function() {
		$("input[id^='datepicker']").datetimepicker({
			scrollInput: false,
			yearOffset:0,
			lang:'en',
			timepicker:false,
			datepicker:true,
			format:'d/m/Y',
			formatDate:'d/m/Y',
			/*minDate:'-1970/01/01',
			onGenerate:function( ct ){
				$(this).find('.xdsoft_date.xdsoft_weekend')
					.addClass('xdsoft_disabled');
			}*/
		});
	});
</script>
<script>
    function cancel() {
        $.post("<?= site_url() ?>search_global", function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        });
    }
    function editSrnKrjAccSave() {
        
        var pCtrlCheck1=''; //ACCESS CONTROL
        if (document.getElementById("pCtrlCheck1").checked == true){
            pCtrlCheck1 = "Y"; 
        }
        else{
            pCtrlCheck1 = "N";
        }
        
        var pCtrlCheck2=''; //LINE TELP
        if (document.getElementById("pCtrlCheck2").checked == true){
            pCtrlCheck2 = "Y"; 
        }
        else{
            pCtrlCheck2 = "N";
        }
        
        //=============================================================
        var pCtrlLokal=''; //
        if (document.getElementById("pCtrlLokal").checked == true){
            pCtrlLokal = "Y"; 
        }
        else{
            pCtrlLokal = "N";
        }
        var pCtrlSljj=''; //
        if (document.getElementById("pCtrlSljj").checked == true){
            pCtrlSljj = "Y"; 
        }
        else{
            pCtrlSljj = "N";
        }
        var pCtrlSli=''; //
        if (document.getElementById("pCtrlSli").checked == true){
            pCtrlSli = "Y"; 
        }
        else{
            pCtrlSli = "N";
        }
        //============================================================
        
        $pJumlahI=$('#pJumlahI').val();
        var arrCardFloor=[""];
        var arrFloor=[""];
        var x=0;
        var arrCardFloorT=''; //ACCESS CONTROL
        for($x=0;$x<$pJumlahI;$x++){
            if (document.getElementById("pCardFloor"+$x).checked == true){
                arrCardFloorT = "Y"; 
            }
            else{
                arrCardFloorT = "N";
            }    
            //arrCardFloor[$x]=document.getElementById('pCardFloor'+$x).value;
            arrCardFloor[$x]=arrCardFloorT;
            arrFloor[$x]=document.getElementById('pFloor'+$x).value;
        }
        
        
        $.post("<?= site_url() ?>search_global/edit_reqSave", {
            pCtrlID: $('#pCtrlID').val(),
            pCType: $('#pCType').val(),
            //pCtrlCheck1: $('#pCtrlCheck1').val(),
            pCtrlCheck1: pCtrlCheck1,
            pCtrlCheck2: pCtrlCheck2,
            pCtrlLokal: pCtrlLokal,
            pCtrlSljj: pCtrlSljj,
            pCtrlSli: pCtrlSli,
            pCardFloor: arrCardFloor,
            pCtrlUserType: $('#pCtrlUserType').val(),
            pNameFor: $('#r_nama').val(),
            pDepartemenFor: $('#r_dept').val(),
            pCtrlDesc: $('#pCtrlDesc').val(),
            pAtasanNik: $('#r_mgrid').val(),
            pCtrlSik: $('#pCtrlSik').val(),
            pDate1: $('#datepicker1').val(),
            pDate2: $('#datepicker2').val(),
            pNikFor: $('#r_id').val(),
            pFloor: arrFloor,
            pPhoneFisik: $('#pPhoneFisik').val(),
            pCardFisik: $('#pCardFisik').val()
        },
        function(data) {
            window.location = '<?php echo base_url(); ?>search_global';
        }
        );
    }
</script>

<!--<div class="container">-->
	<form class="form-horizontal" role="form" method="post" enctype="multipart/form-data"> 
    <input type="hidden" value="<?php echo $cRequestNo; ?>" id="pCtrlID" />
    <input type="hidden" value="<?php echo $cType; ?>" id="pCType" />    
	<div class="col-md-offset-0" id="top">
		<div class="col-md-11">
			<div class="panel panel-default">
				<div class="panel-heading">
					<h4 class="panel-title"><b class="caret"></b><b> Request By</b></h4>
				</div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">
                        <!--
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Status</p></label>
							<div class="col-md-5">
								<select id="UserType" name="UserType" onchange="change_status(this);" class="form-control input-sm">
									<option value="Telkomsel">Telkomsel</option>
									<option value="Vendor">Vendor</option>								
								</select>
							</div>
						</div>
                        -->
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Name<span style="color:red;">*</span></p></label>
							<div class="col-md-7"><input type="text" id="r_name" name="r_name" class="select2 form-control input-sm" placeholder="<?php echo $cName;?>"/>
							<input type="hidden" id="r_nama" name="r_nama" class="select2 form-control input-sm" readonly="" value="<?php echo $cName;?>"/></div>
						</div>
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">ID Number</p></label>
							<div class="col-md-4"><input type="text" value="<?php echo $vCtrlUntukNik;?>" id="r_id" name="r_id" class="form-control input-sm" readonly="" /></div>
						</div>						
					</div>
					<div class="col-xs-12 col-sm-6 col-md-6">
						<div class="form-group">
							<label class="col-md-4"><p class="text-center">Manager</p></label>
							<div class="col-md-7"><input type="text" id="r_mgr" name="r_mgr" class="form-control input-sm" readonly="" value="<?php echo $aAtasanName;?>"/>
							<input type="hidden" id="r_mgrid" name="r_mgrid" class="form-control input-sm" readonly="" value="<?php echo $vCtrlAtasanNik;?>"/></div>
						</div>			
						<div class="form-group" id="r_Dept" name="r_Dept" style="visibility:visible;">
							<label class="col-md-4"><p class="text-center">Departement</p></label>
							<div class="col-md-7"><input type="text" id="r_dept" name="r_dept" class="form-control input-sm" readonly="" value="<?php echo $cOrg;?>"/></div>
						</div>
                        <!--
						<div class="form-group" id="r_JobPos" name="r_JobPos" style="visibility:visible;">
							<label class="col-md-4"><p class="text-center">Job Position</p></label>
							<div class="col-md-8"><input type="text" id="r_job" name="r_job" class="form-control input-sm" readonly=""/></div>
						</div>
                        -->
					</div>
				</div>
			</div>
			<div class="panel panel-default">
				<div class="panel-heading"><h4 class="panel-title"><b class="caret"></b><b> Form</b></h4></div>
				<div class="panel-body">
					<div class="col-xs-12 col-sm-6 col-md-6">				
						<div class="form-group">
							<label class="control-label col-md-4">ID Card</label>
							<div class="col-md-4">
								<select name="pCardFisik" class="form-control input-sm">
									<?php
                            			if($vCtrlCardFisik == '1') {
                            			  ?><option value="0">No</option><?php
                            			  ?><option value="1" selected="">Yes</option><?php
                            			}
                                        else {
                            			  ?><option value="0" selected="">No</option><?php
                            			  ?><option value="1">Yes</option><?php
                            			}
                            		?>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Fixed Phone<span style="color:red;">*</span></label>
							<div class="col-md-5">
								<select name="pPhoneFisik" id="pPhoneFisik" class="form-control input-sm">
									<?php
                            			if(!empty($vCtrlPhoneFisik)) {
                            			  if($vCtrlCardFisik == 'Digital') {
                            			     ?><option value="">-</option><?php
                            			     ?><option value="Analog">Analog</option><?php
                            			     ?><option value="Digital" selected="">Digital</option><?php
                            			  }else {
                            			     ?><option value="">-</option><?php
                            			     ?><option value="Analog" selected="">Analog</option><?php
                            			     ?><option value="Digital">Digital</option><?php
                            			  }
                            			}else {
                            			     ?><option value="" selected="">-</option><?php
                            			     ?><option value="Analog">Analog</option><?php
                            			     ?><option value="Digital">Digital</option><?php
                            			}
                            		?>
								</select>
							</div>
						</div>
						<!--div class="form-group" id="Doc_Ref" style="visibility:hidden;">
							<label class="control-label col-md-5">Doc. Reference</label>
							<div class="col-md-7"><input type="text" value="" name="pCtrlSik" class="form-control input-sm" readonly ></div>
						</div-->						
						<div class="form-group" id="Doc_Ref" >
							<label class="control-label col-md-4">Ref. Doc.<span style="color:red;">*</span></label>
    						<div class="col-md-5">
                            <select name="pCtrlSik" id="pCtrlSik" class="form-control select2"  style="width:230px;">
								<option value="">-- select --</option>
									<?php
                                        foreach($getReference as $ref){
                                        ?>
                                        <option value="<?php echo $ref['SIK_ID']?>" <?php if($vCtrlSikNo==$ref['SIK_ID']){?> selected="" <?php } ?> >
                                            <?php echo $ref['SIK_ID'];?>
                                        </option>
                                        <?php
                                        }
                                        ?>
                            </select>
                            </div>
						</div>						
						<div class="well well-sm" style="text-align:left">
							<div class="form-group">
								<label class="control-label col-md-2">Facility</label>
								<div class="col-md-10">
									<div class="checkbox">
										<ul class="headerGroup">
											<li>
                                                <!--			
												<input type="checkbox" value="Y" id="rFloor" name="rFloor" checked><label>Floor Access</label>-->
                                                <?php
                                                if(!empty($vCtrlCard)) {
                                				    ?>
                     					           <input type="checkbox" id="pCtrlCheck1" value="Y" checked="" />&nbsp;Floor Access
                                                    <?php
                                				}else {
                                				    ?>
                                					<input type="checkbox" id="pCtrlCheck1" value="N"/>&nbsp;Floor Access
                                                    <?php
                                				}?>
												<ul class="group">
                                                    <!--
													<?php $i=0;
													foreach($floor_active as $row){
														$pValue = $row['MST_FLOOR_DESC'];
													?>
														<li>
															<input type="checkbox" id="cekFloor<?php echo $i;?>" name="cekFloor<?php echo $i;?>" value="Y" checked><label><?php echo $pValue;?></label>
															<input type="hidden" id="pFloor<?php echo $i;?>" name="pFloor<?php echo $i;?>" value="<?php echo $pValue;?>"/>
														</li>
													<?php 
														$i++;
													} ?>
													<input type="hidden" id="TotFloorRow" name="TotFloorRow" value="<?php echo $i;?>"/>
                                                    -->
                                                    <?php 
                                                    $i=0;
                                                    foreach($getDetail2 as $row){
                                                        $pKey 	= $row['MST_FLOOR_ID'];
                        			                    $pValue = $row['MST_FLOOR_DESC']; //DAPATKAN NILAINYA
                                                        $getDetail3=$this->sGlobal_model->getDetail3EditAcc($vCtrlCard,$pValue);
                                                        foreach($getDetail3 as $a){
                                                            $cnt = $a['CNT'];
                                                        }
                                                        if($i == 9) {
                                                            ?><br/><?php
                        								}
                                                        //JIKA ADA NILAINYA
                        								if($cnt > 0) {
                        								    ?>
                                                            <li>
                                                                <input type="checkbox" id="pCardFloor<?php echo $i;?>" value="Y" checked="" />&nbsp;<?php echo $pValue;?>&nbsp;&nbsp;
                                                            </li>
                                                            <?php
                        								}
                                                        else {
                        								    ?>
                                                            <li>
                                                                <input type="checkbox" id="pCardFloor<?php echo $i;?>" value="N" />&nbsp;<?php echo $pValue;?>&nbsp;&nbsp;
                                                            </li>
                                                            <?php
                        								}
                        								?><input type="hidden" id="pFloor<?php echo $i;?>" value="<?php echo $pValue;?>" /><?php
                        								$i++;
                                                    }
                                                    ?>
                                                    <input type="hidden" id="pJumlahI" value="<?php echo $i; ?>" />
                                                    
												</ul>
											</li>
										</ul>
									</div>
									<div class="checkbox">
										<ul class="headerGroup">
											<li>
                                                <!--				
												<input type="checkbox" value="Y" id="rLine" name="rLine" checked><label>Telephone Line</label>-->
                                                <?php
                                                if(!empty($vCtrlTelp)) {
                                				    ?>
                                					<input type="checkbox" id="pCtrlCheck2" value="Y" checked="" />&nbsp;Telephone Line
                                                    <?php
                                				}else {
                                				    ?>
                                					<input type="checkbox" id="pCtrlCheck2" value="N" />&nbsp;Telephone Line
                                                    <?php
                                				}?>
												<ul class="group">
                                                    <!--
													<li><label>SLI</label><input id="ceksli" name="ceksli" type="checkbox" value="Y" checked></li>
													<li><label>SLJJ</label><input id="ceksljj" name="ceksljj" type="checkbox" value="Y" checked></li>
													<li><label>LOCAL</label><input id="ceklocal" name="ceklocal" type="checkbox" value="Y" checked></li>
                                                    -->
                                                    <?php
                    								foreach($getTelp as $rw) {
                    									$cek = $rw['CNT'];
                    									if($cek > 0) {
                    										?><li><input type="checkbox" id="pCtrlSli" value="Y" checked=""/><label>SLI</label></li><?php
                    									}else {
                    										?><li><input type="checkbox" id="pCtrlSli" value="N"/><label>SLI</label></li><?php
                    									}
                    								}
                    								foreach($getTelp2 as $rw2) {
                    									$cek = $rw2['CNT'];
                    									if($cek > 0) {
                    										?><li><input type="checkbox" id="pCtrlSljj" value="Y" checked=""/><label>SLJJ</label></li><?php
                    									}else {
                    										?><li><input type="checkbox" id="pCtrlSljj" value="N"/><label>SLJJ</label></li><?php
                    									}
                    								}
                    								foreach($getTelp3 as $rw3) {
                    									$cek = $rw3['CNT'];
                    									if($cek > 0) {
                    										?><li><input type="checkbox" id="pCtrlLokal" value="Y" checked=""/><label>LOCAL</label></li><?php
                    									}else {
                    										?><li><input type="checkbox" id="pCtrlLokal" value="N"/><label>LOCAL</label></li><?php
                    									}
                    								}
                							        ?>
												</ul>
											</li>
										</ul>
									</div>
								</div>
							</div>
						</div>
					</div>
					<div class="col-xs-12 col-sm-5 col-md-6">
						<div class="form-group">
							<label class="control-label col-md-4">Order Date</label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>From</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" id="datepicker1" name="G_Date1" value="<?php echo $vCtrlSDate; ?>"/>
								</div>
							</div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4"></label>
							<div class="col-md-6">
								<div class="input-group">
									<span class="input-group-addon"><small>To</small></span>
									<input type="text" class="form-control input-sm" autocomplete="off" id="datepicker2" name="G_Date2" value="<?php echo $vCtrlEDate; ?>"/>
								</div>
							</div>
						</div>			
						<div class="form-group">
							<label class="control-label col-md-4">Request Date</label>
							<div class="col-md-5"><input id="datepicker3" name="pCtrlDate" type="text" value="<?php echo $vCtrlCDate;?>" class="form-control input-sm" readonly="" /></div>
						</div>
						<div class="form-group">
							<label class="control-label col-md-4">Description<span style="color:red;">*</span></label>
							<div class="col-md-6">
								<textarea id="pCtrlDesc" name="pCtrlDesc" class="form-control input-sm" style="min-width:190px;max-width:200px;min-height:100px;max-height:200px;"><?php echo $vCtrlDesc;?></textarea>
							</div>
						</div>
                        <!--
						<div class="form-group">
							<label class="control-label col-md-4">Upload Photo</label>
							<div class="col-md-5">
								<input type="file" id="file" name="file" class="control-label"> <? //onchange="myFunction()" ?>
								<input type="hidden" class="form-control input-sm" id="nama_file" value="">
							</div>
						</div>
                        -->
					</div>
					
					<script type="text/javascript">
					function myFunction()
					{
						/*
						var x = document.getElementById("file");
						var y = document.getElementById("nama_file");
						y.value = x.value;
						*/
					}
					</script>
					
					<div class="col-md-11">
						<!--<div class="form-group">
							<label class="col-md-13" style="color:red">Order harus mendapatkan persetujuan sesuai KD 043/2004 tentang fasilitas telp dinas karyawan.</label>
						</div>-->
						<div class="col-sm-2">
							<button type="button" class="btn btn-primary btn-block" onclick="editSrnKrjAccSave();">Submit</button>
						</div>
                        <div class="col-sm-2">
                            <button type="button" class="btn btn-default btn-block" onclick="cancel();" >Cancel</button>
                        </div>
					</div>
				</div>
			</div>
		</div>
	</div>
	</form>
    <!--    
</div>-->
<script>
$("#r_name").change(function()
{
    //alert(this.id.substr(2));    
	var nik = $(this).val();
	var DataString = {id:nik};
	$.ajax({
			type: "POST",
			url : "<?php echo site_url('search_global/globals_nik_detail')?>",
			dataType: 'json',
			data: DataString,
			success: function(data)
			{
				$("#r_id").val(data.DetailEmp.HR_ID);
                $("#r_nama").val(data.DetailEmp.NAME);
                $("#r_mgrid").val(data.DetailEmp.MANAGER_ID);
				$("#r_mgr").val(data.DetailEmp.MANAGER);
				$("#r_dept").val(data.DetailEmp.ORG);
				$("#r_job").val(data.DetailEmp.JOB_POSITION);														
			}
			
		});
});
</script>

<script type="text/javascript">
	
	function change_status(elm) 
	{
		var v = document.getElementById('r_Dept');
		var w = document.getElementById('r_JobPos');
		var x = document.getElementById('Doc_Ref');
		/*
		var a = document.getElementById('r_id');
		var b = document.getElementById('r_name');
		var c = document.getElementById('r_nama');
		var d = document.getElementById('r_mgr');
		var e = document.getElementById('r_mgrid');		
		var f = document.getElementById('r_dept');	
		var g = document.getElementById('r_job');
		*/		
		if (elm.value=='Vendor') 
		{
			v.style.visibility = 'hidden';
			w.style.visibility = 'hidden';
			x.style.visibility = 'visible';
			/*
			a.value = '';
			b.value = '';
			c.value = '';
			d.value = '';
			e.value = '';
			f.value = '';
			g.value = '';
			*/
		} 
		else 
		{
			v.style.visibility = 'visible';
			w.style.visibility = 'visible';		
			x.style.visibility = 'hidden';	
		}
	}
	
	$('#pCtrlDate').datetimepicker({
		scrollInput:false,
		closeOnDateSelect:true,
		datepicker:true,
		timepicker:false,
		format:'d/m/Y',
		minDate:'-1970/01/01',
		onGenerate:function( ct ){$(this).find('.xdsoft_date.xdsoft_weekend').addClass('xdsoft_disabled');}
	});
	
	function cekDulu(elm)
	{
		var frm = elm.form;
		var reTgl = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
		var reJam = /^\d{1,2}$/;
		var x = document.getElementById('Doc_Ref');
		
		$r_name = $('#r_name').val();
		if ($r_name==""){alert('Requestor tidak boleh kosong!'); document.getElementById('r_name').focus(); eRRor='1'; return false;}
		
		$pPhoneFisik = $('#pPhoneFisik').val();
		if ($pPhoneFisik==""){alert('Fixed Phone tidak boleh kosong!'); document.getElementById('pPhoneFisik').focus(); eRRor='1'; return false;}

		if(x.style.visibility=='visible'){	
			$pCtrlSik = $('#pCtrlSik').val();
			if ($pCtrlSik==""){alert('Referensi Dokumen tidak boleh kosong!'); document.getElementById('pCtrlSik').focus(); eRRor='1'; return false;}
		}
		
		//$pCtrlDesc = $('#pCtrlDesc').val();
		//if ($pCtrlDesc==""){alert('Description tidak boleh kosong!'); document.getElementById('pCtrlDesc').focus(); eRRor='1'; return false;}
		
		if (!frm.elements['G_Date1'].value.match(reTgl)||!frm.elements['G_Date2'].value.match(reTgl)) {
			alert('Tanggal harus diisi (Format: dd/mm/yyyy)');
			return false;
		} else {
			var a = frm.elements['G_Date1'].value.match(reTgl);
			var b = frm.elements['G_Date2'].value.match(reTgl);
			var sTime = a[3] + a[2] + a[1];
			var eTime = b[3] + b[2] + b[1];
			if (sTime >= eTime) {
				alert('Tanggal akhir harus lebih besar dari tanggal awal (Format: dd/mm/yyyy)');
				frm.elements['G_Date2'].focus();
				return false;
			}
		}
		if (frm.elements['pCtrlDesc'].value.length==0) {
			alert('Description tidak boleh kosong!');
			frm.elements['pCtrlDesc'].focus();
			return false;
		}
				
	}

</script>
